package com.springboot.example.monitor;

import com.springboot.example.monitor.domain.db.User;
import com.springboot.example.monitor.mapper.UserMapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;

import javax.annotation.Resource;

/**
 * 作者: guo yao
 * 日期: 2016年01月14日
 * 时间: 下午14:45
 */
@SpringBootApplication
@MapperScan("com.springboot.example.monitor.mapper")
public class SpringBootMain extends SpringBootServletInitializer implements CommandLineRunner {

    @Resource
    private UserMapper userMapper;

    @Override
    public void run(String... strings) throws Exception {
        // 执行一些代码
        System.out.println(userMapper.select(new User()));
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(SpringBootMain.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(SpringBootMain.class, args);
    }

    @Bean
    public com.springboot.example.monitor.interceptor.DialectStatementHandlerInterceptor dialectStatementHandlerInterceptor() {
        System.out.println("=====================dialectStatementHandlerInterceptor==========");
        return new com.springboot.example.monitor.interceptor.DialectStatementHandlerInterceptor();
    }

    @Bean
    public com.springboot.example.monitor.interceptor.DialectResultSetHandlerInterceptor dialectResultSetHandlerInterceptor() {
        System.out.println("=====================dialectResultSetHandlerInterceptor==========");
        return new com.springboot.example.monitor.interceptor.DialectResultSetHandlerInterceptor();
    }
}
